#include "GameListener.h"
#include "HardwareBuffer.h"

CGameListener::CGameListener(void)
{
}


CGameListener::~CGameListener(void)
{
}

void CGameListener::OnInitialize()
{
	CCamera* pCamera = CRoot::InstancePtr()->GetRenderSystem()->GetActiveRenderWindow()->GetCamera();
	pCamera->SetPosition(0.0f, -10.0f, 0.0f);
	pCamera->LookAt(0.0f, 10.0f, 0.0f);
	//pCamera->Pitch(MATH_PI/2);

	CSceneManager* pSceneManager = CRoot::InstancePtr()->GetSceneManager();

	//CEntity*	pEntity = pSceneManager->CreateEntity("howlet","butterfly1.ms3d");

	//CTexture* pTexture =
	//	CRoot::InstancePtr()->GetRenderSystem()->GetActiveRenderWindow()->GetVideoManager()->CreateTextureFromFile("xx","butterfly4.bmp");
	//pEntity->GetMaterial()->GetFragmentProgram()->GetShaderParamTable()->SetValue("$decalTex", pTexture);
	////pEntity->GetMaterial()->m_fillMode = FILLMODE_WIREFRAME;

	//CSceneNode* pSceneNode = pSceneManager->CreateSceneNode("sceneNode");
	//pEntity->Attach(pSceneNode);
	//pSceneNode->SetPosition(0, 0, 0);
	//pSceneNode->Pitch(-MATH_PI/2);

	CTerrain* pTerrain = pSceneManager->CreateTerrain("xx", "terrain.png", 16);
	pTerrain->GetMaterial()->m_fillMode = FILLMODE_WIREFRAME;
	//m_uint16 count = pTerrain->GetTriangleCount();
	//++count;
}

void CGameListener::OnShutDown()
{

}

void CGameListener::OnRenderStart(CRenderTarget* rw)
{
	CRoot::InstancePtr()->GetInputSystem()->Update();
}

void CGameListener::OnRender(CRenderTarget* rw)
{
	if (CInputSystem::InstancePtr()->GetKeyBoard()->IsKeyDown(KEY_Z))
	{
		int a = 0;
		a++;
		int b = a;
	}

	//float fps = 0.0f;
	if (CInputSystem::InstancePtr()->GetKeyBoard()->IsKeyDown(KEY_W))
	{
		//fps = rw->GetFPS();
		int a = 0;
		a++;
		int b = a;
	}

	if (CInputSystem::InstancePtr()->GetMouse()->IsLMouseDown())
	{
		int a = 0;
		a++;
		int b = a;
	}
}
 
void CGameListener::OnRenderEnd(CRenderTarget* rw)
{

}